/**
 * 
 */
package optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.selection;

import optimization.naturalOptimization.evolutionaryAlgorithm.EvolutionaryAlgorithm;
import optimization.naturalOptimization.population.individual.Individual;

/**
 * Creates a new Selector for a plus selection strategy.
 * 
 * @author Kevin Wagner
 * @version 1.0
 */
public class PlusSelector extends Selector {

	/**
	 * Creates a new Plus Selector.
	 * 
	 * @param parentEA
	 */
	public PlusSelector(EvolutionaryAlgorithm parentEA) {
		super(parentEA);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator
	 * .EvolutionaryOperator#work()
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public void work() {
		Individual[] ind = new Individual[getParentEA().getLambda()
				+ getParentEA().getMu()];
		int count = 0;
		for (int i = 0; i < getParentEA().getMu(); i++) {
			ind[count] = getParentEA().getParentPopulation().getIndividual(i);
			count++;
		}
		for (int i = 0; i < getParentEA().getLambda(); i++) {
			ind[count] = getParentEA().getProgenyPopulation().getIndividual(i);
			count++;
		}
		sortIndividuals(ind);
		getParentEA().getParentPopulation().removeAllIndividuals();
		for (int i = 0; i < getParentEA().getMu(); i++) {
			ind[i].setParentPopulation(getParentEA().getParentPopulation());
			getParentEA().getParentPopulation().addIndividual(ind[i]);

		}
		getParentEA().getProgenyPopulation().removeAllIndividuals();
	}

	

}
